#include <iostream>
#include <cstdlib>
#include <unistd.h>
#include "RingQueue.hpp"

using std::cout;
using std::endl;

void *pr(void* args)
{
    RingQueue<int> *rq = static_cast<RingQueue<int> *>(args);
    while (true)
    {
        int a = rand() % 10 + 1;
        rq->push(a);
        cout << "生产数据为：" << a << endl;
        sleep(1);
    }
}

void* cr(void* args)
{
    RingQueue<int> *rq = static_cast<RingQueue<int> *>(args);
    while (true)
    {
        int a = 0;
        rq->pop(&a);

        cout << "消费数据为：" << a << endl;
        sleep(1);
    }
}

int main()
{

    pthread_t p, c;
    RingQueue<int> *RQ = new RingQueue<int>;
    srand((size_t)time(nullptr) ^ getpid() ^ 0x73432379);

    pthread_create(&p, nullptr, pr, RQ);
    pthread_create(&c, nullptr, cr, RQ);



    pthread_join(p, nullptr);
    pthread_join(c, nullptr);

    return 0;
}